<template>
  <div class="personal-center">
    <div class="personal-header">
      <img :src="userStore.avatarUrl(user.avatar)" alt="头像" class="avatar"/>
      <div class="user-basic">
        <div class="username">{{ user.username }}</div>
        <div class="userid">ID：{{ user.userId }}</div>
      </div>
    </div>
    <div class="personal-info">
      <div class="info-item"><span>手机号：</span>{{ user.phone }}</div>
      <div class="info-item"><span>注册时间：</span>{{ user.createdAt ? user.createdAt.slice(0,10) : '' }}</div>
      <div class="info-item"><span>评分：</span>{{ user.rating }}</div>
      <div class="info-item"><span>胜场：</span>{{ user.wins }}</div>
      <div class="info-item"><span>败场：</span>{{ user.losses }}</div>
      <div class="info-item"><span>平局：</span>{{ user.draws }}</div>
    </div>
    <!--   
    <div class="personal-actions">
      <button @click="showAvatarModal = true">修改头像</button>
      <button @click="showPwdModal = true">修改密码</button>
    </div>
    -->
    <!-- 修改头像弹窗 -->
    <div v-if="showAvatarModal" class="modal">
      <div class="modal-content">
        <h3>修改头像</h3>
        <input type="file" @change="onAvatarChange" />
        <div class="modal-actions">
          <button @click="updateAvatar">确定</button>
          <button @click="showAvatarModal = false">取消</button>
        </div>
      </div>
    </div>
    <!-- 修改密码弹窗 -->
    <div v-if="showPwdModal" class="modal">
      <div class="modal-content">
        <h3>修改密码</h3>
        <input type="password" v-model="oldPwd" placeholder="原密码" />
        <input type="password" v-model="newPwd" placeholder="新密码" />
        <div class="modal-actions">
          <button @click="updatePwd">确定</button>
          <button @click="showPwdModal = false">取消</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useUserStore } from '../../stores/user'
const userStore = useUserStore()
const user = userStore.user

const showAvatarModal = ref(false)
const showPwdModal = ref(false)
const oldPwd = ref('')
const newPwd = ref('')
const avatarFile = ref(null)

function onAvatarChange(e) {
  avatarFile.value = e.target.files[0]
}

function updateAvatar() {
  // 这里应调用后端接口上传头像，成功后刷新用户信息
  alert('模拟：头像已更新')
  showAvatarModal.value = false
}

function updatePwd() {
  if (!oldPwd.value || !newPwd.value) {
    alert('请输入完整信息')
    return
  }
  // 这里应调用后端接口修改密码
  alert('模拟：密码已修改')
  showPwdModal.value = false
  oldPwd.value = ''
  newPwd.value = ''
}
</script>

<style scoped>
.personal-center {
  width: 100%;
  min-herght: 80vh;
  margin: 48px auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 24px rgba(60,60,60,0.10);
  padding: 36px 28px 28px 28px;
  font-family: "Segoe UI", "PingFang SC", Arial, sans-serif;
}
.personal-header {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-bottom: 28px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 18px;
}
.avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 3px solid #3b82f6;
  background: #e0e7ff;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(59,130,246,0.10);
}
.user-basic {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.username {
  font-size: 1.5rem;
  font-weight: 700;
  color: #2056b3;
  letter-spacing: 1px;
}
.userid {
  font-size: 1rem;
  color: #64748b;
}
.personal-info {
  margin: 28px 0 18px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 24px;
}
.info-item {
  font-size: 1.08rem;
  color: #333;
  background: #f6f8fa;
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
}
.info-item span {
  color: #2563eb;
  font-weight: 600;
  margin-right: 6px;
}
.personal-actions {
  text-align: center;
  margin-bottom: 8px;
}
.personal-actions button {
  margin: 0 14px;
  padding: 8px 32px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(90deg, #2563eb 60%, #38bdf8 100%);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(59,130,246,0.08);
}
.personal-actions button:hover {
  background: linear-gradient(90deg, #38bdf8 60%, #2563eb 100%);
}
.modal {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 32px 28px;
  min-width: 320px;
  box-shadow: 0 2px 12px rgba(60,60,60,0.12);
  text-align: center;
}
.modal-content input {
  display: block;  
  margin: 16px auto;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #e0e7ef;
  font-size: 1rem;
}
.modal-actions {
  margin-top: 18px;
}
.modal-actions button {
  margin: 0 10px;
  padding: 6px 22px;
  border-radius: 6px;
  border: none;
  background: #2056b3;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}
.modal-actions button:hover {
  background: #3b82f6;
}
</style>